﻿<%@ Page Title="Strategic Asset Management Las Vegas: Scraping" Language="C#" MasterPageFile="~/Site2.master" AutoEventWireup="true"
    CodeBehind="AdminScrapping.aspx.cs" Inherits="LenderClearingHouse.AdminScrapping"
    ValidateRequest="false" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content3" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="cphPageHeader" runat="server">
    Scraping
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphMain" runat="server">
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function ScrapeRecon() {
                var allWin = new ActiveXObject("Shell.Application").Windows();
                for (var ii = 0; ii < allWin.Count; ii++) {
                    var win1 = allWin.Item(ii);

                    if ((win1 != null) && (win1.LocationURL.indexOf("recontrustco") + 1)) {
                        document.getElementsByName("<%= hfRecon.UniqueID %>").item(0).value = win1.document.documentElement.outerHTML;
                        __doPostBack("<%= pnlRecon.UniqueID %>", "");
                        return false;
                    }
                }
                alert("No web page for scrapping found");
                return false;
            }
        </script>
        <script type="text/javascript">
            function ScrapePriority() {
                var allWin = new ActiveXObject("Shell.Application").Windows();
                for (var ii = 0; ii < allWin.Count; ii++) {
                    var win1 = allWin.Item(ii);
                    
                    if ((win1 != null) && (win1.LocationURL.indexOf("priorityposting") + 1)) {
                        var div = win1.document.getElementById("ctl00_ContentPlaceHolder1_DataPager1");

                        if (div != null) {
                            document.getElementsByName("<%= hfPriority.UniqueID %>").item(0).value =
                                win1.document.documentElement.outerHTML;
                            __doPostBack("<%= pnlPriority.UniqueID %>", "");
                        }
                        else alert("No data for scrapping found");
                        return false;
                    }
                }
                alert("No web page for scrapping found");
                return false;
            }
        </script>
        <script type="text/javascript">
            function ScrapeLps() {
                var allWin = new ActiveXObject("Shell.Application").Windows();
                for (var ii = 0; ii < allWin.Count; ii++) {
                    var win1 = allWin.Item(ii);

                    if ((win1 != null) && (win1.LocationURL.indexOf("lpsasap") + 1)) {
                        var div = win1.document.getElementById("gridTS");

                        if (div != null) {
                            document.getElementsByName("<%= hfLps.UniqueID %>").item(0).value = div.outerHTML;
                            __doPostBack("<%= pnlLps.UniqueID %>", "");
                        }
                        else alert("No data for scrapping found");
                        return false;
                    }
                }
                alert("No web page for scrapping found");
                return false;
            }
        </script>
        <script type="text/javascript">
            function ScrapeNdsCorp() {
                var viewedSites = "";

                var allWin = new ActiveXObject("Shell.Application").Windows();
                for (var ii = 0; ii < allWin.Count; ii++) {
                    var win1 = allWin.Item(ii);
                    //if (win1 != null) viewedSites = viewedSites + win1.LocationURL + "\n";

                    if ((win1 != null) && (win1.LocationURL.indexOf("ndscorp") + 1)) {
                        var div = win1.document.getElementById("upListView");

                        if (div != null) {
                            document.getElementsByName("<%= hfNdsCorp.UniqueID %>").item(0).value = div.innerHTML;
                            __doPostBack("<%= pnlNdsCorp.UniqueID %>", "");
                        }
                        else alert("No data for scrapping found");
                        return false;
                    }
                }
                alert("No web page for scrapping found\n" + viewedSites);
                return false;
            }
        </script>
        <script type="text/javascript">
            function validateUpload(source, arguments) {
                arguments.IsValid = $find('<%= upload.ClientID %>').validateExtensions();
            }
        </script>
    </telerik:RadCodeBlock>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default">
    </telerik:RadAjaxLoadingPanel>
    <asp:Panel ID="pnlCsvFileImport" runat="server">
        <fieldset>
            <legend>CSV File Import</legend>
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td id="tdImportType" runat="server" width="200px">
                        <asp:RadioButtonList ID="rblImportType" runat="server">
                            <asp:ListItem Selected="True">Master List</asp:ListItem>
                            <asp:ListItem>Working List</asp:ListItem>
                            <asp:ListItem>NV Legal</asp:ListItem>
                            <asp:ListItem>Title Info</asp:ListItem>
                            <asp:ListItem>SDREO</asp:ListItem>
                            <asp:ListItem>LVREO</asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                    <td>
                        <telerik:RadUpload ID="upload" runat="server" InputSize="70" OverwriteExistingFiles="True"
                            TargetFolder="~/Uploads" AllowedFileExtensions=".csv,.xls" Width="500px" ControlObjectsVisibility="None"
                            ReadOnlyFileInputs="True" FocusOnLoad="True">
                        </telerik:RadUpload>
                        <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="validateUpload"
                            Display="Dynamic"><span style="FONT-SIZE: 11px;color:Red;">Please select CSV or XLS file</span>
                        </asp:CustomValidator>
                        <asp:Label ID="lbDocumentsUploaded" runat="server" Font-Size="11px"></asp:Label>
                        <br />
                        <br />
                        <asp:Button ID="btnImport" runat="server" Text="Import file" OnClick="btnImport_Click" />
                    </td>
                </tr>
            </table>
        </fieldset>
    </asp:Panel>
    <br />
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Width="100%" HorizontalAlign="NotSet"
        LoadingPanelID="RadAjaxLoadingPanel1" Visible="False">
        <fieldset id="fieldsetScraping" runat="server">
            <legend>Scraping</legend>
            <asp:Panel ID="pnlScrapeLvreoAdmin" runat="server" Visible="false">
                <br />
                Press "Scrape" to scrape Assessor Information LVREO
                <br />
                <br />
                <asp:Button ID="btnScrapeLvreoAdmin" runat="server" Text="Scrape"
                    onclick="btnScrapeLvreoAdmin_Click" />
            </asp:Panel>
            <asp:Panel ID="pnlScrape" runat="server">
                <br />
                Please select the site to scrape and press "Scrape"
                <br />
                <br />
                <asp:RadioButtonList ID="listSites" runat="server">
                    <asp:ListItem Selected="True" Value="AS">Assessor Information</asp:ListItem>
                    <asp:ListItem Value="LPS">LPS Asap - No Auto Page Function</asp:ListItem>
                    <asp:ListItem Value="RECON">Recon Trust</asp:ListItem>
                    <asp:ListItem Value="NdsCorp">Nds Corp - No Auto Page Function</asp:ListItem>
                    <asp:ListItem Value="PRIOR">Priority Posting - No Auto Page Function</asp:ListItem>
                    <asp:ListItem Value="ASLVREO">Assessor Information LVREO ONLY</asp:ListItem>
                </asp:RadioButtonList>
                <br />
                <asp:Button ID="btnScrapeNew" runat="server" Text="Scrape" 
                    onclick="btnScrapeNew_Click" />&nbsp;
                <asp:Button ID="btnScrape" runat="server" Text="Scrape All" 
                    OnClick="btnScrape_Click" />&nbsp;
                <asp:Button ID="btnClearSelected" runat="server" Text="Clear Selected" 
                    onclick="btnClearSelected_Click" />&nbsp;
                <asp:Button ID="btnClearAllBids" runat="server" Text="Clear All Bids" 
                    onclick="btnClearAllBids_Click" />
            </asp:Panel>
            <asp:Panel ID="pnlNewScrape" runat="server" Visible="False">
                <asp:Label ID="lbMessage" runat="server" Text="Label"></asp:Label>
                <br />
                <asp:Button ID="btnNewScrape" runat="server" Text="New Scrape" OnClick="btnNewScrape_Click" />
            </asp:Panel>
            <asp:Panel ID="pnlNdsCorp" runat="server" Visible="False">
                <a href="http://www.ndscorp.com/FsSales/PendingSales.aspx" target="_blank">Press here</a>
                to open NdsCorp website and then press Scrape to scrape the page you want
                <br />
                <br />
                <input id="btnNdsCorpScrape" type="button" value="Scrape" onclick="return ScrapeNdsCorp()" />
                <asp:HiddenField ID="hfNdsCorp" runat="server" Value="" />
            </asp:Panel>
            <asp:Panel ID="pnlPriority" runat="server" Visible="False">
                <a href="http://www.priorityposting.com/PPPAdvancedWebSearch/Pages/AdvancedSearchPage.aspx"
                    target="_blank">Press here</a> to open Priority website and then press Scrape
                to scrape the page you want
                <br />
                <br />
                <input id="Button1" type="button" value="Scrape" onclick="return ScrapePriority()" />
                <asp:HiddenField ID="hfPriority" runat="server" Value="" />
            </asp:Panel>
            <asp:Panel ID="pnlRecon" runat="server" Visible="False">
                <a href="https://www.recontrustco.com/upcoming_counties.aspx?state=Nevada" target="_blank">
                    Press here</a> to open Recon Trust website, then select county and then press
                Scrape to scrape the page you want
                <br />
                <br />
                <input id="Button2" type="button" value="Scrape" onclick="return ScrapeRecon()" />
                <asp:HiddenField ID="hfRecon" runat="server" Value="" />
            </asp:Panel>
            <asp:Panel ID="pnlLps" runat="server" Visible="False">
                <a href="http://www.lpsasap.com/login.aspx" target="_blank">Press here</a> to open
                LPS Asap website and then press Scrape to scrape the page you want
                <br />
                <br />
                <input id="Button3" type="button" value="Scrape" onclick="return ScrapeLps()" />
                <asp:HiddenField ID="hfLps" runat="server" Value="" />
            </asp:Panel>
        </fieldset>
    </telerik:RadAjaxPanel>
</asp:Content>
